const axios = require('axios')

function getHome() {
    return new Promise((resolve, reject) => {
        axios({
            method: 'POST',
            url: 'https://api2.ppwang.com/index.php?c=goods',
            head: {
                'User- Agent': 'pi pi wang/ 6.0.1(iPhone; iOS 10.3.2; Scale / 2.00)',
                'Content - Type': 'application/x-www-form-urlencoded',
                'versioncode': '11412',
                'platform': 'iOS'
            },
            data: {
                '_': 1559620903.504284, // 前面是当前时间秒数，后面6位不知为何
                json: [
                    {
                        'cmd': '2021'
                    }
                ]
            }
        })
            .then(({ data: { '2021': { data = [] } } }) => {
                // console.table(data)
                resolve(data)

            })
            .catch((error) => {
                // console.log(error)
                reject(error)

            })
    })

}
function getList({ id, page = 1 }) {
    return new Promise((resolve, reject) => {
        let ppJson = JSON.stringify([{
            'cmd': '2022',
            'label_package_id': id,
            'page': page
        }])

        axios({
            method: 'GET',
            url: 'https://api2.ppwang.com/index.php',
            head: {
                'User- Agent': 'pi pi wang/ 6.0.1(iPhone; iOS 10.3.2; Scale / 2.00)',
                'versioncode': '11412',
                'platform': 'iOS'
            },
            params: {
                c: 'goods',
                '_': 1559624346.224447, // 前面是当前时间秒数，后面6位不知为何
                json: ppJson
            }
        })
            .then(({ data: { '2022': { data = [] } } }) => {
                console.table(data)
                resolve(data)

            })
            .catch((error) => {
                console.log(error)
                reject(error)

            })
    })


}
module.exports = { getHome, getList }